from urllib.request import Request

import requests

from basic基础层.base专门处理request请求 import RequestBase


class Url:
    _URL_COUPON_SELECT = "/adminapi/shop/goods/coupon"
    _URL_COUPON_ADD = "/adminapi/shop/goods/coupon"
    _URL_COUPON_EDIT = "/adminapi/shop/goods/coupon/edit"
    _URL_COUPON_INCALID = "/adminapi/shop/goods/coupon/invalid"
    _URL_COUPON_DEL="/adminapi/shop/goods/coupon"


class Marketing(RequestBase, Url):
    def goods_coupon_select(self):
        """优惠券查询"""
        return self._get(self.goods_coupon_select.__name__, self._URL_COUPON_SELECT)

    def goods_coupon_add(self, title, price):
        """优惠券添加"""
        data = {
            'title': title,
            'price': price,
            'type': 1,
            'limit': 2,
            'receive_type': 1,
            'remain_count': 1000,
            'threshold': 2,
            'limit_count': 1,
            'min_condition_money': 1,
            'length': 30,
            'receive_type_time': 2,
            'valid_type': 1,
            'receive_time': [
                '2025-03-14T09:00:54.675Z',
                '2025-04-13T09:00:54.675Z',
            ],
            'valid_time': '2025-04-13T09:00:54.675Z',
        }

        return self._post(self.goods_coupon_add.__name__, self._URL_COUPON_ADD, data)

    def goods_coupon_edit(self, coupon_id, title, price,*args,**kwargs):
        """优惠券编辑"""
        data = {
            'title': title,
            'price': price,
            'type': 1,
            'limit': 2,
            'receive_type': 1,
            'remain_count': 1000,
            'threshold': 2,
            'limit_count': 1,
            'min_condition_money': '0.00',
            'length': 30,
            'receive_type_time': 2,
            'valid_type': 1,
            'receive_time': [
                '2025-03-14T09:38:51.903Z',
                '2025-04-13T09:38:51.903Z',
            ],
            'valid_time': '2025-04-13 17:00:54',
            'id': coupon_id,
            'start_time': 0,
            'end_time': 0,
            'receive_count': 0,
            'status': 1,
            'create_time': '2025-03-14 17:03:40',
            'valid_start_time': '2025-03-14 17:03:40',
            'valid_end_time': '2025-04-13 17:00:54',
            'sort': 0,
            'receive_status': 1,
            'sum_count': '不限量',
            'receive_use_count': 0,
            'receive_expire_count': 0,
        }
        return self._put(self.goods_coupon_edit.__name__, self._URL_COUPON_EDIT + f"/{coupon_id}", data)

    def goods_coupon_invalid(self,coupon_id):
        """优惠券关闭"""
        data = {
            "json": {'showSuccessMessage': True}
        }
        return self._put(self.goods_coupon_invalid.__name__, self._URL_COUPON_INCALID+f"/{coupon_id}", data)

    def goods_coupon_del(self,coupon_id):
        """优惠券删除"""
        return self._delete(self.goods_coupon_del.__name__, self._URL_COUPON_DEL+f"/{coupon_id}")

    def goods_coupon_records(self):
        """优惠券领取查询"""
        pass

    def goods_coupon_detail(self):
        """优惠券详情"""
        pass


if __name__ == '__main__':
    obj = Marketing()
    obj.goods_coupon_select()
